const path = require("path")
const fs = require('fs'); // 引入fs模块





exports.resolve = function (dir) {
  return path.resolve(__dirname, dir)
}


class yxScripts {
  static isAnalyz(Envname) {
    return process.env.NODE_ENV === (Envname ? Envname : "analyz")
  }
  static isProduction(Envname) {
    return process.env.NODE_ENV === (Envname ? Envname : "production")
  }

  static isDll(Envname) {
    return process.env.NODE_ENV === (Envname ? Envname : "dll")
  }

  static findPath(paths = "../src/index") {
    var list = ['.js', '.jsx', '.ts', '.tsx']
    list.some(function (item, index) {
      var existPath = path.join(__dirname, `../src/index${item}`)
      var isExits = fs.existsSync(existPath)
      if (isExits) {
        paths = existPath
        return true
      }
    })
    return paths
  }
}

exports.yxScripts = yxScripts


// function deleteall(path) {
//   var files = [];
//   if (fs.existsSync(path)) {
//     files = fs.readdirSync(path);
//     files.forEach(function (file, index) {
//       var curPath = path + "/" + file;
//       if (fs.statSync(curPath).isDirectory()) { // recurse
//         deleteall(curPath);
//       } else { // delete file
//         fs.unlinkSync(curPath);
//       }
//     });
//     fs.rmdirSync(path);
//   }
// };